package cdu.javaendwork.Controller.Admin.AdoptionMore;

import cdu.javaendwork.model.sqlModel.Pet;
import cdu.javaendwork.service.Impl.AdoptionMore.PetServiceImpl;
import cdu.javaendwork.service.Interface.AdoptionMore.PetService;
import cdu.javaendwork.util.pageHelp.PageHelper;
import cdu.javaendwork.util.pageHelp.PageInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/admin/pet_list")
public class PetListController extends HttpServlet {
    PageHelper pageHelper = new PageHelper();

    PetService petService=new PetServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String sPage=req.getParameter("page");
        int pageSize=3;
        int pageIndex=(sPage == null || sPage.equals("")) ? 1 : Integer.parseInt(sPage);

        List<Pet> petList = petService.Petlimit(pageIndex,pageSize);
        PageInfo pageInfo=pageHelper.all("Pet", pageIndex, pageSize);

        req.setAttribute("petList",petList);
        req.setAttribute("pageInfo",pageInfo);

        System.out.println(petList);
        System.out.println(pageInfo);

        req.getRequestDispatcher("pet_manage.jsp").forward(req,resp);
    }
}
